#include <iostream>

class Singleton //饿汉单例模式
{
public:
    static Singleton& GetInstance()
    {
        // if(_eton != nullptr)   return _eton;
        return _eton;
    }

    int GetData()
    {
        return _data;
    }
private:
    int _data;
private:
    static Singleton _eton;//类内静态成员变量需要在类外定义，此处只是声明；
    Singleton() :_data(99){
        std::cout << "单例模式：饿汉（构造函数完成）" << std::endl;
    }
    Singleton(const Singleton&) = delete;
    ~Singleton(){}
};

Singleton Singleton::_eton;

int main1()
{
    //std::cout << Singleton::GetInstance().GetData() <<std::endl;
    return 0;
}

class Singlenton_l//懒汉单例模式
{
private:
    Singlenton_l() :_data(66){
        std::cout << "单例模式：懒汉（构造函数完成）" << std::endl;
    }
    Singlenton_l(const Singlenton_l&) = delete;
    ~Singlenton_l(){}
private:
    int _data;
public:
    static Singlenton_l& GetInstance()
    {
        static Singlenton_l _eton;
        return _eton;
    }
    int GetData()
    {
        return _data;
    }
};

int main()
{
    //std::cout << Singlenton_l::GetInstance().GetData() << std::endl;
    return 0;
}